package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wechat.domain.Campsite;
import com.ruoyi.wechat.service.ICampsiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 营地营位表Controller
 * 
 * @author ruoyi
 * @date 2024-11-05
 */
@Anonymous
@RestController
@RequestMapping("/wechat/campsite")
public class WxCampsiteController extends BaseController
{
    @Autowired
    private ICampsiteService campsiteService;

    /**
     * 查询营地营位表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Campsite campsite)
    {
        startPage();
        List<Campsite> list = campsiteService.selectCampsiteList(campsite);
        return getDataTable(list);
    }

    /**
     * 导出营地营位表列表
     */
    @Log(title = "营地营位表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Campsite campsite)
    {
        List<Campsite> list = campsiteService.selectCampsiteList(campsite);
        ExcelUtil<Campsite> util = new ExcelUtil<Campsite>(Campsite.class);
        util.exportExcel(response, list, "营地营位表数据");
    }

    /**
     * 获取营地营位表详细信息
     */
    @GetMapping(value = "/{campsiteId}")
    public AjaxResult getInfo(@PathVariable("campsiteId") String campsiteId)
    {
        return success(campsiteService.selectCampsiteByCampsiteId(campsiteId));
    }

    /**
     * 新增营地营位表
     */
    @Log(title = "营地营位表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Campsite[] campsites)
    {
        return toAjax(campsiteService.insertCampsites(campsites));
    }

    /**
     * 修改营地营位表
     */
    @Log(title = "营地营位表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Campsite campsite)
    {
        return toAjax(campsiteService.updateCampsite(campsite));
    }

    /**
     * 删除营地营位表
     */
    @Log(title = "营地营位表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{campsiteIds}")
    public AjaxResult remove(@PathVariable String[] campsiteIds)
    {
        return toAjax(campsiteService.deleteCampsiteByCampsiteIds(campsiteIds));
    }
}
